Contents | < Browse | Browse >
EVAL expression
OVERVIEW
========
Operators:
+ Add
- Subtract
* Multiply
/ Divide
& Logical and
! Logical or
= Poke into memory
? Peek out of memory
Prefixes:
+ Positive number
- Negative number
% Binary number
$ Hexadecimal number
& Hexadecimal APTR converted to BPTR
! Hexadecimal BPTR converted to APTR
^ Filename containing number
* EVAL evaluates the "expression" as a reverse polish expression,
and displays the answer in decimal and hex notation. Reverse
Polish Notation (RPN) is used in Forth and in Hewlett Packard
calculators (I have a HP48GX which has really a great functionality,
but unfortunately is a one-way product: If something is defective, you
have to throw it away in most cases). It is based on how arithmetic
is actually done at the lowest possible level. RPN allows calculating
complex expressions without using brackets.
eg. eval 4 5 +
This gives the answer 9. When a number is found, it is "pushed"
onto the arithmetic stack. The + always adds the last two numbers
on the stack.
eg. eval 7 2 3 + -
This gives the answer 2. It is the same as (7 - (2 + 3)). See,
7 is first pushed onto the stack, followed by 2, then 3. The +
adds together the 2 and 3 and leaves the result 5 on the stack.
Which means that the number 7 followed by 5 are left on the
stack. The - subtracts the last entry (5) on the stack from the
one before it (7), leaving the result 2.
eg. 12 * (3 + 9) > eval 12 3 9 + *
(15 - 4) * (6 + 18) > eval 15 4 - 6 18 + *
(6 * ((87 + 13) / (2 * 25))) > eval 6 87 13 + 2 25 * / *
* EVAL only performs 32 bit integer arithmetic.
Negative numbers are prefixed with - .(hexadecimal they are
shown as a 31 bit integer with bit 32 set, as usual)
Prefixing positive numbers with + is optional.
eg. eval +5 -3 + {results in 2 hex:$00000002}
eval -5 3 + {results in -2 hex:$fffffffe}
* EVAL supports decimal, hexadecimal and binary numbers.
If you prefix the number with $, the number is hex
If you prefix the number with %, it is binary.
Programmers: For BPTR-APTR conversion you can use & to specify
a hexadecimal APTR when asked for a BPTR and vice versa with !.
eg. eval $c00000 $a0 16 * +
* EVAL can also be used to perform base conversions (to dec or hex)
eg. eval $ca
eval %10110001
eval 45
eval &5a8
* The & allows logical AND'ing. And ! allows logical OR'ing.
The ? is similar to PEEK in BASIC.
Conversely, = is similar to POKE in BASIC
eg. eval $80 $21 $08 ! ! $aa &
eval $67 %11001011 &
eval $c00000 ?
This prints out the long word in memory locations $c00000 - $c00003.
eval $aa55aa55aa $40000 =
This pokes the long word $aa55aa55aa into locations $40000 thru $40003
and prints out what was in before.
* For environment handling you can specify the value of an
environment variable with ^ followed by the name.
To store the result in a variable, redirect the output.
eg. eval >ENV:aa ^ENV:bb 1 +
This adds 1 to the value in ENV:bb and stores the result in ENV:aa
* If the result was 0 an error (fail-level 10) will be returned.
If it was negative, a warn (5) returns. (Not when redirecting output)